package com.example.demo.service.impl;

import com.example.demo.Util.BaseUtil;
import com.example.demo.mapper.MonitorcodeInfoMapper;
import com.example.demo.mapper.MonitorobjInfoMapper;
import com.example.demo.service.AccessTestResultHandler;
import com.example.demo.service.TestAccessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;

/**
 * Created by tanjun on 2022-01-09.
 */
@Component
public class BaseAccessService {

    @Autowired
    AccessTestResultHandler accessTestResultHandler;

    @Autowired
    MonitorobjInfoMapper monitorobjInfoMapper;

    @Autowired
    MonitorcodeInfoMapper monitorcodeInfoMapper;

    private ConfigurableApplicationContext applicationContext;

    public void setApplicationContext(ConfigurableApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    /**
     * 根据监控对象类型获取合适的测试连通性服务实例。
     * @param monitorobjType
     * @return
     */
    public TestAccessService getTestAccessServiceByMonitorType(String monitorobjType){
        switch (monitorobjType){
            case "webServiceAccess":
                //return testWebServiceAccessService;
                return (TestAccessService)BaseUtil.getBean("testWebServiceAccessService");
            case "portAccess":
                //return testIpportAccessService;
                return (TestAccessService)BaseUtil.getBean("testIpportAccessService");
            case "ipAccess":
                //return testIPAccessService;
                return (TestAccessService)BaseUtil.getBean("testIPAccessService");
            case "databaseAccess":
                //return testDatabaseAccessService;
                return (TestAccessService)BaseUtil.getBean("testDatabaseAccessService");

        }
        return null;
    }

}
